import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:fluttercalcpokers/odds/bean/card_bean.dart';
import 'package:fluttercalcpokers/utils/style_config.dart';

// ignore: must_be_immutable
class PokerSelect extends StatefulWidget {
  List<CardBean> cardList;
  final pokerSelectItems;
  final cleanItem;

  PokerSelect({Key key, this.cardList, this.pokerSelectItems, this.cleanItem})
      : super(key: key);

  @override
  _PokerSelectState createState() => _PokerSelectState();
}

class _PokerSelectState extends State<PokerSelect> {
  @override
  Widget build(BuildContext context) {
    Widget itemBuilder(item, key) {
      Widget button = RaisedButton(
        onPressed: () {
          widget.pokerSelectItems(item, key);
        },
        child: Text(
          item.getValue(),
          style: TextStyle(fontSize: fontSize_16, color: Colors.white),
        ),
      );
      Widget _notSelect = Container(
        width: ScreenUtil().setWidth(120),
        height: ScreenUtil().setHeight(80),
        color: Colors.black,
      );
      return Container(
        width: ScreenUtil().setWidth(120),
        height: ScreenUtil().setHeight(80),
        child: item.select == true ? _notSelect : button,
      );
    }

    Widget pokerSelectListBuilder() {
      List<Widget> widgets = [];
      Widget content;
      for (int i = 0; i < widget.cardList.length; i++) {
        CardBean item = widget.cardList[i];
        widgets.add(itemBuilder(item, i));
      }

      content = Container(
        width: ScreenUtil().setWidth(750),
        height: ScreenUtil().setHeight(100),
        child: Row(
          children: <Widget>[
            Container(
              width: ScreenUtil().setWidth(600),
              height: ScreenUtil().setHeight(100),
              padding: EdgeInsets.only(left: 10.0, right: 10.0),
              child: Flex(
                direction: Axis.horizontal,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: widgets,
              ),
            ),
            Container(
              width: ScreenUtil().setWidth(120),
              height: ScreenUtil().setHeight(100),
              child: Material(
                color: Color.fromRGBO(255, 255, 255, 0),
                child: InkWell(
                  onTap: () {
                    widget.cleanItem();
                  },
                  child: Container(
                    width: ScreenUtil().setWidth(120),
                    height: ScreenUtil().setHeight(75),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage("images/btn.png"),
                          fit: BoxFit.contain),
                      borderRadius: BorderRadius.all(
                        Radius.circular(
                          ScreenUtil().setWidth(5),
                        ),
                      ),
                    ),
                    child: Center(
                      child: Text(
                        "清空",
                        style: TextStyle(
                          fontSize: ScreenUtil().setWidth(24),
                          color: Color.fromRGBO(232, 213, 187, 1),
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      );
      return content;
    }

    return Container(
        padding: EdgeInsets.all(5.0), child: pokerSelectListBuilder());
  }
}
